/**
 * copyright (c) by handpay 2012
 */
package com.handpay.zztong.hp.adapter;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.handpay.framework.utils.CommonUtils;
import com.handpay.framework.utils.DateUtils;
import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.base.activity.ZZTongActivity;
import com.handpay.zztong.hp.bean.AppealInfo;


public class QueryAppealsAdapter extends BaseAdapter {
    // 交易账单列表
    private List<AppealInfo> appealInfoList;
    private LayoutInflater inflater;
    private Activity mActivity;

    public QueryAppealsAdapter(ZZTongActivity activity, List<AppealInfo> appealInfoList) {
        this.appealInfoList = appealInfoList;
        mActivity = activity;
        inflater = LayoutInflater.from(activity);
    }

    @Override
    public int getCount() {
        return this.appealInfoList.size();
    }

    @Override
    public Object getItem(int position) {
        return this.appealInfoList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AppealPojo appealPojo = new AppealPojo();
        AppealInfo appealInfo = this.appealInfoList.get(position);
        if (convertView == null || convertView.getTag() == null) {
            convertView = inflater.inflate(R.layout.appeal_item, null);
            appealPojo.appeal_trans_time_tv = (TextView) convertView.findViewById(R.id.appeal_trans_time_tv);
            appealPojo.appeal_trans_sn_tv = (TextView) convertView.findViewById(R.id.appeal_trans_sn_tv);
            appealPojo.appeal_trans_amount_tv = (TextView) convertView.findViewById(R.id.appeal_trans_amount_tv);
            appealPojo.appeal_time_tv = (TextView) convertView.findViewById(R.id.appeal_time_tv);
            appealPojo.appeal_sn_tv = (TextView) convertView.findViewById(R.id.appeal_sn_tv);
            appealPojo.appeal_status_tv = (TextView) convertView.findViewById(R.id.appeal_status_tv);
            appealPojo.trans_status_tv = (TextView) convertView.findViewById(R.id.trans_status_tv);
            appealPojo.appeal_card_tv = (TextView) convertView.findViewById(R.id.appeal_card_tv);
            convertView.setTag(appealPojo);
        } else {
            appealPojo = (AppealPojo) convertView.getTag();
        }
        appealPojo.appeal_trans_time_tv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(appealInfo.getTransTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
        appealPojo.appeal_trans_sn_tv.setText(appealInfo.getTransSN());
        if(!"null".equals(appealInfo.getTransferAmount())){
            appealPojo.appeal_trans_amount_tv.setText(CommonUtils.formatMoney(Double.valueOf(appealInfo.getTransferAmount()) / 100));
        }
        appealPojo.appeal_time_tv.setText(DateUtils.formatDateToString(DateUtils.formatStringToDate(appealInfo.getAppealTime(), "yyyyMMddHHmmss"), "yyyy-MM-dd HH:mm:ss"));
        appealPojo.appeal_sn_tv.setText(appealInfo.getAppealId());
        appealPojo.trans_status_tv.setText(String.valueOf(appealInfo.getPaymentStatus()));
        appealPojo.appeal_card_tv.setText(appealInfo.getOutputCardNo());
        //1：已申诉待回复
        //2：已回复
        String _appealStatus;
        if (appealInfo.getAppealStatus() == 0) {
            _appealStatus = "已申诉待回复";
        } else {
            _appealStatus = "已回复";
        }
        appealPojo.appeal_status_tv.setText(_appealStatus);
        return convertView;
    }

    class AppealPojo {
        public TextView appeal_trans_time_tv = null;
        public TextView appeal_trans_sn_tv = null;
        public TextView appeal_trans_amount_tv = null;
        public TextView appeal_time_tv = null;
        public TextView appeal_sn_tv = null;
        public TextView appeal_status_tv = null;

        public TextView appeal_card_tv = null;

        public TextView trans_status_tv = null;
    }
}